package demo.day07;

import java.util.Arrays;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/25-07-25-16:15
 * @Description：demo.day07   二维数组   实现杨辉三角
 */
public class YHTriangle_Test {
    public static void main(String[] args) {
        int[][] arr = new int[5][];
        for (int i = 0; i < 5; i++) {
            //初始化创建
            arr[i] = new int[i+1];
        }
        //赋值
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if(j==0 || j == arr[i].length-1){
                    arr[i][j] = 1;
                }else{
                    //当前值 = 上一行的同列 + 上一行的前一列
                    arr[i][j] = arr[i-1][j] +arr[i-1][j-1];
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j < arr.length-1; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
    }
}
